using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace AjGenesisStudio.Commands
{
    class SaveAsCommand : Command
    {
        public override bool Execute()
        {
            return Execute(Global.Instance.MainForm.GetActiveDocument());
        }

        public bool Execute(Documents.Document doc)
        {
            if (doc == null)
                return true;

            string file = SaveCommand.ShowSave(System.IO.Path.GetExtension(doc.FilePath));

            if (!string.IsNullOrEmpty(file))
            {
                Global.Instance.StartWork("Saving " + Path.GetFileName(file));
                
                doc.editor.Save(file);
                doc.FilePath = file;

                Global.Instance.EndWork();
            }

            return true;
        }
    }
}
